home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WBITMAP.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  7.8 KB  |  254 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. #ifndef _WBITMAP_HPP_INCLUDED
  12. #define _WBITMAP_HPP_INCLUDED
  13. #pragma once
  14.  
  15. #ifndef _WNO_PRAGMA_PUSH
  16. #pragma pack(push,8);
  17. #pragma enum int;
  18. #endif
  19.  
  20. #ifndef _WOBJECT_HPP_INCLUDED
  21. #  include "wobject.hpp"
  22. #endif
  23. #ifndef _WARRAY_HPP_INCLUDED
  24. #  include "warray.hpp"
  25. #endif
  26. #ifndef _WCOLOR_HPP_INCLUDED
  27. #  include "wcolor.hpp"
  28. #endif
  29. #ifndef _WRESID_HPP_INCLUDED
  30. #  include "wresid.hpp"
  31. #endif
  32. #ifndef _WICON_HPP_INCLUDED
  33. #  include "wicon.hpp"
  34. #endif
  35. #ifndef _WPALETTE_HPP_INCLUDED
  36. #  include "wpalette.hpp"
  37. #endif
  38. #ifndef _WBUFFER_HPP_INCLUDED
  39. #  include "wbuffer.hpp"
  40. #endif
  41. #ifndef _WFILPATH_HPP_INCLUDED
  42. #  include "wfilpath.hpp"
  43. #endif
  44.  
  45. class WPoint;
  46. class WCanvas;
  47. class WBitmapReference;
  48.  
  49. enum WStockBitmap {
  50.     WSBitmapFirst,
  51.     WSBitmapClose = WSBitmapFirst,
  52.     WSBitmapUpArrow,
  53.     WSBitmapDownArrow,          WSBitmapDnArrow = WSBitmapDownArrow,
  54.     WSBitmapLeftArrow,          WSBitmapLfArrow = WSBitmapLeftArrow,
  55.     WSBitmapRightArrow,         WSBitmapRgArrow = WSBitmapRightArrow,
  56.     WSBitmapReduce,
  57.     WSBitmapZoom,
  58.     WSBitmapRestore,
  59.     WSBitmapCombo,
  60.     WSBitmapMNArrow,
  61.     WSBitmapSize,
  62.     WSBitmapCheck,
  63.     WSBitmapCheckBoxes,
  64.     WSBitmapBtnCorners,
  65.     WSBitmapBTSize,
  66.     WSBitmapUpArrowD,
  67.     WSBitmapDownArrowD,         WSBitmapDnArrowD = WSBitmapDownArrowD,
  68.     WSBitmapLeftArrowD,         WSBitmapLfArrowD = WSBitmapLeftArrowD,
  69.     WSBitmapRightArrowD,        WSBitmapRgArrowD = WSBitmapRightArrowD,
  70.     WSBitmapReduceD,
  71.     WSBitmapZoomD,
  72.     WSBitmapRestoreD,
  73.     WSBitmapUpArrowI,
  74.     WSBitmapDownArrowI,         WSBitmapDnArrowI = WSBitmapDownArrowI,
  75.     WSBitmapLeftArrowI,         WSBitmapLfArrowI = WSBitmapLeftArrowI,
  76.     WSBitmapRightArrowI,        WSBitmapRgArrowI = WSBitmapRightArrowI,
  77.  
  78.     WSBitmapLastPlusOne,
  79.     WSBitmapLast = WSBitmapLastPlusOne - 1,
  80. };
  81.  
  82. class WCMCLASS WBitmap : public WObject {
  83.     WDeclareSubclass( WBitmap, WObject );
  84.  
  85.     public:
  86.  
  87.         /**********************************************************
  88.          * Constructors and Destructors
  89.          *********************************************************/
  90.  
  91.         // Construct
  92.  
  93.         WBitmap();
  94.         WBitmap( WStockBitmap bitmap );
  95.         WBitmap( const WBitmap & src, WUInt newWidth=0, WUInt newHeight=0,
  96.                  WBool forceCreateNew=FALSE );
  97.         WBitmap( const WResourceID & id, WModuleHandle module=_ApplicationModule );
  98.         WBitmap( const WChar *file, const WResourceID & id,
  99.                  WBool loadLibraryAsDataOnly=FALSE );
  100.         WBitmap( const WChar *file, WBool monochrome );
  101.         WBitmap( WBitmapHandle hdl, WBool deleteHandle=FALSE );
  102.         WBitmap( WDeviceHandle hdc, WUInt width, WUInt height );
  103.         WBitmap( WUInt width, WUInt height, WUInt planes, WUInt bitsPerPel );
  104.         WBitmap( const WIcon & icon, const WColor * backColor=NULL );
  105.         WBitmap( const WIcon & icon, WCanvas * port, const WPoint & pt );
  106.         WBitmap( const WIcon & icon, WCanvas * port );
  107.         WBitmap( const WBuffer & buffer );
  108.  
  109.         // Destruct
  110.  
  111.         ~WBitmap();
  112.  
  113.         // Assignment
  114.  
  115.         WBitmap & operator=( const WBitmap & bitmap );
  116.         WBitmap & operator=( WStockBitmap bitmap );
  117.  
  118.         // Equality
  119.  
  120.         int operator==( const WBitmap & bmp ) const;
  121.         int operator!=( const WBitmap & bmp ) const;
  122.  
  123.         /************************************************************
  124.          * Properties
  125.          ************************************************************/
  126.  
  127.         // Handle
  128.  
  129.         WBitmapHandle GetHandle() const;
  130.  
  131.         // HandleDetached
  132.  
  133.         WBool GetHandleDetached() const;
  134.  
  135.         // Height
  136.  
  137.         WUInt GetHeight() const;
  138.  
  139.         // Palette
  140.  
  141.         WPalette GetPalette() const;
  142.  
  143.         // Valid
  144.  
  145.         WBool GetValid() const;
  146.  
  147.         // Width
  148.  
  149.         WUInt GetWidth() const;
  150.  
  151.         /************************************************************
  152.          * Methods
  153.          ************************************************************/
  154.  
  155.         // Clear
  156.         //
  157.         //     Prepare the object for re-use.  Deletes old bitmap
  158.         //     handle if appropriate.
  159.  
  160.         WBool Clear();
  161.  
  162.         // Create
  163.         //
  164.         //     Create a new bitmap.  Clears old one first.
  165.  
  166.         WBool Create( WStockBitmap bitmap );
  167.         WBool Create( const WBitmap & src, WUInt newWidth=0,
  168.                       WUInt newHeight=0, WBool forceCreateNew=FALSE );
  169.         WBool Create( const WResourceID & id, WModuleHandle module=_ApplicationModule );
  170.         WBool Create( const WChar *file, const WResourceID & id,
  171.                       WBool loadLibraryAsDataOnly=FALSE );
  172.         WBool Create( const WChar *file, WBool monochrome );
  173.         WBool Create( WBitmapHandle hdl, WBool deleteHandle=FALSE );
  174.         WBool Create( WDeviceHandle hdc, WUInt width, WUInt height );
  175.         WBool Create( WUInt width, WUInt height, WUInt planes,
  176.                       WUInt bitsPerPel );
  177.         WBool Create( const WIcon & icon, const WColor * backColor=NULL );
  178.         WBool Create( const WIcon & icon, WCanvas * port, const WPoint & pt );
  179.         WBool Create( const WIcon & icon, WCanvas * port );
  180.         WBool Create( const WBuffer & buffer );
  181.  
  182.         // MakePalette
  183.  
  184.         WBool MakePalette();
  185.  
  186.         // DetachHandle
  187.  
  188.         WBool DetachHandle();
  189.     
  190.         // MapColor
  191.  
  192.         WBool MapColor( const WColor & mapFrom, const WColor & mapTo );
  193.  
  194.         // Save
  195.         //
  196.         //     Save the bitmap out as a .BMP file.
  197.  
  198.         WBool Save( const WFilePath & filename, WUInt bitsPerPixel=0,
  199.                     WDeviceHandle dev=NULLHDEV ) const;
  200.         WBool Save( WBuffer & buffer, WUInt bitsPerPixel=0,
  201.                     WDeviceHandle dev=NULLHDEV ) const;
  202.     
  203.         /***********************************************************
  204.          * Static Properties
  205.          ***********************************************************/
  206.  
  207.         // NullBitmap
  208.  
  209.         static const WBitmap & GetNullBitmap(); // not an empty bitmap...
  210.  
  211.         /************************************************************
  212.          * Static Methods
  213.          ************************************************************/
  214.  
  215.         // IsValidHandle
  216.         //
  217.         //     Returns TRUE if the given handle is valid.  Can
  218.         //     optionally specify whether or not a null handle
  219.         //     is "valid".
  220.  
  221.         static WBool IsValidHandle( WBitmapHandle handle,
  222.                                     WBool nullValid=FALSE );
  223.  
  224.  
  225.         /***********************************************************
  226.          * Internal
  227.          ***********************************************************/
  228.  
  229.         WUShort GetOriginalBitCount() const;
  230.  
  231.     protected:
  232.         WBool GetWidthHeight();
  233.     
  234.     private:
  235.         WBitmapReference *      _bitmapRef;
  236. };
  237.  
  238. extern template WArrayReference<WBitmap>;
  239. extern template WArray<WBitmap>;
  240. typedef WArray<WBitmap>                 WBitmapArray;
  241.  
  242. #ifdef _DEBUG
  243. #define W_ISBITMAPHANDLE(h) CHECKGDI(WBitmap::IsValidHandle((WBitmapHandle)h))
  244. #else
  245. #define W_ISBITMAPHANDLE(h)
  246. #endif
  247.  
  248. #ifndef _WNO_PRAGMA_PUSH
  249. #pragma enum pop;
  250. #pragma pack(pop);
  251. #endif
  252.  
  253. #endif // _WBITMAP_HPP_INCLUDED
  254.